package com.shop.dao;

import com.shop.model.Student;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class RegisterDAO {
    public Boolean register(String studentId,String phone, String password) {
        Student student = null;
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        int resultSet = 0;

        try {
            connection = DBUtil.getConnection();
            String sql = "insert into student(studentId,phone,password) values(?,?,?)";
            if (connection != null) {
                preparedStatement = connection.prepareStatement(sql);
            }
            preparedStatement.setString(1, studentId);
            preparedStatement.setString(2, phone);
            preparedStatement.setString(3, password);

             resultSet = preparedStatement.executeUpdate();

        } catch (SQLException ex) {
            throw new RuntimeException(ex);
        }finally {
            DBUtil.close(connection,preparedStatement);
        }
        if(resultSet!=0){
            return true;
        }else{
            return false;
        }
    }
}

